<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>React Router</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="../../../libs/react/16.2.0/umd/react.development.js"></script>
    <script src="../../../libs/react-dom/16.2.0/umd/react-dom.development.js"></script>
    <script src="../../../libs/react-router-dom/4.2.2/react-router-dom.js"></script>
    <script src="../../../libs/babel-standalone/6.26.0/babel.min.js"></script>
</head>

<body>
    <div id='root'></div>
</body>
<script type="text/babel">

    const BasicExample = () => (
        <Router>
            <div>
                <ul>
                    <li><Link to="/">首页</Link></li>
                    <li><Link to="/about">关于</Link></li>
                    <li><Link to="/topics">主题</Link></li>
                </ul>

                <hr />

                <Route exact path="/" component={Home} />
                <Route path="/about" component={About} />
                <Route path="/topics" component={Topics} />
            </div>
        </Router>
    )

    const Home = () => (
        <div>
            <h2>Home</h2>
        </div>
    )

    const About = () => (
        <div>
            <h2>About</h2>
        </div>
    )

    const Topics = ({ match }) => (
        <div>
            <h2>Topics</h2>
            <ul>
                <li>
                    <Link to={`${match.url}/rendering`}>
                        Rendering with React
        </Link>
                </li>
                <li>
                    <Link to={`${match.url}/components`}>
                        Components
        </Link>
                </li>
                <li>
                    <Link to={`${match.url}/props-v-state`}>
                        Props v. State
        </Link>
                </li>
            </ul>

            <Route path={`${match.url}/:topicId`} component={Topic} />
            <Route exact path={match.url} render={() => (
                <h3>Please select a topic.</h3>
            )} />
        </div>
    )

    const Topic = ({ match }) => (
        <div>
            <h3>{match.params.topicId}</h3>
        </div>
    )

    const { BrowserRouter, Route, Link } = ReactRouterDOM;
    const Router = BrowserRouter;

    ReactDOM.render(
        <BasicExample />,
        document.getElementById('root')
    );
</script>

</html>